home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / sysdeps / mach / hurd / mig-reply.c < prev    next >
C/C++ Source or Header  |  1994-05-30  |  2KB  |  76 lines

  1. /* Copyright (C) 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <mach.h>
  20. #include <hurd/threadvar.h>
  21.  
  22. #define GETPORT \
  23.   mach_port_t *portloc = \
  24.     (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY)
  25. #define reply_port (use_threadvar ? *portloc : global_reply_port)
  26.  
  27. static int use_threadvar;
  28. static mach_port_t global_reply_port;
  29.  
  30. /* These functions are called by MiG-generated code.  */
  31.  
  32. /* Called by MiG to get a reply port.  */
  33. mach_port_t
  34. __mig_get_reply_port (void)
  35. {
  36.   GETPORT;
  37.  
  38.   if (reply_port == MACH_PORT_NULL)
  39.     reply_port = __mach_reply_port ();
  40.  
  41.   return reply_port;
  42. }
  43.  
  44. /* Called by MiG to deallocate the reply port.  */
  45. void
  46. __mig_dealloc_reply_port (void)
  47. {
  48.   mach_port_t port;
  49.  
  50.   GETPORT;
  51.  
  52.   port = reply_port;
  53.   reply_port = MACH_PORT_NULL;    /* So the mod_refs RPC won't use it.  */
  54.   __mach_port_mod_refs (__mach_task_self (), port,
  55.             MACH_PORT_RIGHT_RECEIVE, -1);
  56. }
  57.  
  58.  
  59. /* Called at startup with STACK == NULL.  When per-thread variables are set
  60.    up, this is called again with STACK set to the new stack being switched
  61.    to, where per-thread variables should be set up.  */
  62. void
  63. __mig_init (void *stack)
  64. {
  65.   use_threadvar = stack != 0;
  66.  
  67.   if (use_threadvar)
  68.     {
  69.       /* Recycle the reply port used before multithreading was enabled.  */
  70.       mach_port_t *portloc = (mach_port_t *)
  71.     __hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY, stack);
  72.       *portloc = global_reply_port;
  73.       global_reply_port = MACH_PORT_NULL;
  74.     }
  75. }
  76.